﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Project_ScansiaPacific
{
    public partial class FrMain : DevComponents.DotNetBar.Office2007Form
    {
        public FrMain()
        {
            InitializeComponent();
        }
        public void Enable(string Users)
        {
            Process prs = new Process();
            SqlConnection Conn = prs.Connect();
            SqlCommand cmd = new SqlCommand();
            try
            {
                Conn.Open();
                string check = @"select KhuVuc from dbo.Users where UsersName='" + Users + "'";
                cmd.Connection = Conn;
                cmd.CommandText = check;
                //MessageBox.Show(check);
                check = cmd.ExecuteScalar().ToString();
                if (check == "KV1" || check == "KV2" || check == "KV3" || check == "KV4" || check == "KV5"||check=="KhoGo"||check=="kt")
                {
                    if (check == "KV1")
                    {
                        Mni_HeThong.Visible = true;
                        Mni_KV1.Visible = true;
                        Mni_KV2.Visible = false;
                        Mni_KeHoachSX.Visible = false;
                        //Mni_DinhMuc.Visible = true;
                        //Mni_ImportDB.Visible = true;
                        Mni_ThongKe.Visible = false;
                        //Mni_ThongTin.Visible = true;
                        Mni_KV3.Visible = false;
                        Mni_KV4.Visible = false;
                        Mni_KV5.Visible = false;
                        Mni_KhoGo.Visible = false;
                    }
                    if (check == "KV2")
                    {
                        Mni_HeThong.Visible = true;
                        Mni_KV1.Visible = false;
                        Mni_KV2.Visible = true;
                        Mni_KeHoachSX.Visible = false;
                        //Mni_DinhMuc.Visible = true;
                        //Mni_ImportDB.Visible = true;
                        Mni_ThongKe.Visible = false;
                        //Mni_ThongTin.Visible = true;
                        Mni_KV3.Visible = false;
                        Mni_KV4.Visible = false;
                        Mni_KV5.Visible = false;
                        Mni_KhoGo.Visible = false;
                    }
                    if (check == "KV3")
                    {
                        Mni_HeThong.Visible = true;
                        Mni_KV1.Visible = false;
                        Mni_KV2.Visible = false;
                        Mni_KeHoachSX.Visible = false;
                        //Mni_DinhMuc.Visible = true;
                        //Mni_ImportDB.Visible = true;
                        Mni_ThongKe.Visible = false;
                        //Mni_ThongTin.Visible = true;
                        Mni_KV3.Visible = true;
                        Mni_KV4.Visible = false;
                        Mni_KV5.Visible = false;
                        Mni_KhoGo.Visible = false;
                    }
                    if (check == "KV4")
                    {
                        Mni_HeThong.Visible = true;
                        Mni_KV1.Visible = false;
                        Mni_KV2.Visible = false;
                        Mni_KeHoachSX.Visible = false;
                        //Mni_DinhMuc.Visible = true;
                        //Mni_ImportDB.Visible = true;
                        Mni_ThongKe.Visible = false;
                        //Mni_ThongTin.Visible = true;
                        Mni_KV3.Visible = false;
                        Mni_KV4.Visible = true;
                        Mni_KV5.Visible = false;
                        Mni_KhoGo.Visible = false;
                    }
                    if (check == "KV5")
                    {
                        Mni_HeThong.Visible = true;
                        Mni_KV1.Visible = false;
                        Mni_KV2.Visible = false;
                        Mni_KeHoachSX.Visible = false;
                        //Mni_DinhMuc.Visible = true;
                        //Mni_ImportDB.Visible = true;
                        Mni_ThongKe.Visible = false;
                        //Mni_ThongTin.Visible = true;
                        Mni_KV3.Visible = false;
                        Mni_KV4.Visible = false;
                        Mni_KV5.Visible = true;
                        Mni_KhoGo.Visible = false;
                    }
                    if (check == "KhoGo")
                    {
                        Mni_HeThong.Visible = true;
                        Mni_KV1.Visible = false;
                        Mni_KV2.Visible = false;
                        Mni_KeHoachSX.Visible = false;
                        //Mni_DinhMuc.Visible = true;
                        //Mni_ImportDB.Visible = true;
                        Mni_ThongKe.Visible = false;
                        //Mni_ThongTin.Visible = true;
                        Mni_KV3.Visible = false;
                        Mni_KV4.Visible = false;
                        Mni_KV5.Visible = false;
                        Mni_KhoGo.Visible = true;
                    }
                    if (check == "kt")
                    {
                        Mni_HeThong.Visible = true;
                        Mni_KV1.Visible = false;
                        Mni_KV2.Visible = false;
                        Mni_KeHoachSX.Visible = false;
                        //Mni_DinhMuc.Visible = true;
                        //Mni_ImportDB.Visible = true;
                        Mni_ThongKe.Visible = true;
                        //Mni_ThongTin.Visible = true;
                        Mni_KV3.Visible = false;
                        Mni_KV4.Visible = false;
                        Mni_KV5.Visible = false;
                        Mni_KhoGo.Visible = false;
                    }
                }
                else
                {
                    Mni_HeThong.Visible = true;
                    Mni_KV1.Visible = true;
                    Mni_KV2.Visible = true;
                    Mni_KeHoachSX.Visible = true;
                    //Mni_DinhMuc.Visible = true;
                    //Mni_ImportDB.Visible = true;
                    Mni_ThongKe.Visible = true;
                    //Mni_ThongTin.Visible = true;
                    Mni_KV3.Visible = true;
                    Mni_KV4.Visible = true;
                    Mni_KV5.Visible = true;
                    Mni_KhoGo.Visible = true;
                }
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Conn.Close();
                cmd.Dispose();
            }
           // Mni_KhoGo.Visible = true;
            
           

        }
        public void Disable()
        {
            Mni_KhoGo.Visible = false;
            Mni_HeThong.Visible= false;
            Mni_KV1.Visible = false;
            Mni_KeHoachSX.Visible = false;
            Mni_KV2.Visible = false;
            Mni_ImportDB.Visible = false;
            Mni_ThongKe.Visible = false;
            Mni_ThongTin.Visible = false;
            Mni_KV3.Visible = false;
            Mni_KV4.Visible = false;
            Mni_KV5.Visible = false;
        }
        public void User(string Users)
        {
            lb_User.Text = Users;
        }
        private void Mni_DangNhap_Click(object sender, EventArgs e)
        {
            FrDangNhap FrDN = new FrDangNhap();
            FrDN.MdiParent = this;
            FrDN.Show();
        }
        private void FrMain_Load(object sender, EventArgs e)
        {
            Mni_DangNhap_Click(null, null);
            Disable();
        }

        private void Mni_Thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Mni_DoiMatKhau_Click(object sender, EventArgs e)
        {
            FrDoiMatKhau FrDMK = new FrDoiMatKhau();
            FrDMK.MdiParent = this;
            FrDMK.Show();
        }
        private void Mni_NhaCungCap_Click(object sender, EventArgs e)
        {
            FrNhaCungCap FrNCC = new FrNhaCungCap();
            FrNCC.MdiParent = this;
            FrNCC.Show();
        }

        private void Mni_KhachHang_Click(object sender, EventArgs e)
        {
            FrKhachHang FrKH = new FrKhachHang();
            FrKH.MdiParent = this;
            FrKH.Show();
        }

        private void Mni_GoXeKien_Click(object sender, EventArgs e)
        {
            FrNhapKhoXeKien FrGXK = new FrNhapKhoXeKien();
            FrGXK.MdiParent = this;
            FrGXK.Show();
            FrGXK.User(lb_User.Text);

        }

        private void Mni_LoSay_Click(object sender, EventArgs e)
        {
            FrNhapGoSay FrGS = new FrNhapGoSay();
            FrGS.MdiParent = this;
            FrGS.Show();
            FrGS.User(lb_User.Text);
        }

        private void Mni_QLNX_Click(object sender, EventArgs e)
        {
            FrQLNhapKho FrQLNX = new FrQLNhapKho();
            FrQLNX.MdiParent = this;
            FrQLNX.Show();
            FrQLNX.User(lb_User.Text);
        }

       

        private void Mni_QLXK_Click(object sender, EventArgs e)
        {
            FrQLXuatKho FrQLXK = new FrQLXuatKho();
            FrQLXK.MdiParent = this;
            FrQLXK.Show();
        }

        private void Mni_KeHoachSP_Click(object sender, EventArgs e)
        {
            FrKeHoach FrKHSP = new FrKeHoach();
            FrKHSP.MdiParent = this;
            FrKHSP.Show();
        }

        private void Mni_ChiTietThieu_Click(object sender, EventArgs e)
        {
            FrKH_ChiTietThieu FrKHMG = new FrKH_ChiTietThieu();
            FrKHMG.MdiParent = this;
            FrKHMG.Show();
        }

        private void Mni_Import_SLTK_Click(object sender, EventArgs e)
        {
            FrImport_Data FrI = new FrImport_Data();
            FrI.MdiParent = this;
            FrI.Show();
        }

        private void Mni_TTSanPham_Click(object sender, EventArgs e)
        {
            FrTTSanPham FrTTSP = new FrTTSanPham();
            FrTTSP.MdiParent = this;
            FrTTSP.Show();
        }

        private void Mni_GoDauVao_Click(object sender, EventArgs e)
        {
            FrKHMuaGo FrMG = new FrKHMuaGo();
            FrMG.MdiParent = this;
            FrMG.Show();
        }

        private void Mni_NhapCTLoi_Click(object sender, EventArgs e)
        {
            FrTKChonMau FrChonMau = new FrTKChonMau();
            FrChonMau.MdiParent = this;
            FrChonMau.Show();
        }

        private void Mni_ThongKeCTLoi_Click(object sender, EventArgs e)
        {
            FrTKReport FrTK = new FrTKReport();
            FrTK.MdiParent = this;
            FrTK.Show();
        }

        private void Mni_LenXuongPhieu_Click(object sender, EventArgs e)
        {
            FrKV2 Fr = new FrKV2();
            Fr.MdiParent = this;
            Fr.Show();
            Fr.Users(lb_User.Text);
        }

        private void Mni_TKHangLoai_Click(object sender, EventArgs e)
        {
            FrTKHangLoai FrHL = new FrTKHangLoai();
            FrHL.MdiParent = this;
            FrHL.Show();
            FrHL.Users(lb_User.Text);
        }

        private void Mni_KTG_Click(object sender, EventArgs e)
        {
            FrKTG KTG = new FrKTG();
            KTG.MdiParent = this;
            KTG.Show();
            KTG.Users(lb_User.Text);
            
        }

        private void Mni_LXP_Click(object sender, EventArgs e)
        {
            FrKV2_XP Fr = new FrKV2_XP();
            Fr.MdiParent = this;
            Fr.Show();
            Fr.Users(lb_User.Text);
        }

        private void Mni_KhoTam_Click(object sender, EventArgs e)
        {
            FrKV3_KTam Fr = new FrKV3_KTam();
            Fr.MdiParent = this;
            Fr.Show();
            Fr.Users(lb_User.Text);
        }

        private void Mni_KhoTP_Click(object sender, EventArgs e)
        {
            FrKhoThanhPham Fr = new FrKhoThanhPham();
            Fr.MdiParent = this;
            Fr.Show();
            Fr.Users(lb_User.Text);
        }

        private void Mni_NghiemThuGo_Click(object sender, EventArgs e)
        {
            FrNghiemThuGo Fr = new FrNghiemThuGo();
            Fr.MdiParent = this;
            Fr.Show();
        }

        private void Mni_DMGKV1_Click(object sender, EventArgs e)
        {
            FrTKNLVaoRa Fr = new FrTKNLVaoRa();
            //Fr.MdiParent = this;
            Fr.Show();
        }

        private void Mni_DGGS_Click(object sender, EventArgs e)
        {
            FrDGCLGS Fr = new FrDGCLGS();
            Fr.MdiParent = this;
            Fr.Show();
            Fr.Users(lb_User.Text);
        }

        private void Mni_NKMayBao_Click(object sender, EventArgs e)
        {
            FrNKMayBao Fr = new FrNKMayBao();
            Fr.MdiParent = this;
            Fr.Show();
        }

        private void Mni_NhapKho_Click(object sender, EventArgs e)
        {
            Fr_KhoGo Fr = new Fr_KhoGo();
            Fr.MdiParent = this;
            Fr.Show();
            Fr.Users(lb_User.Text);
        }

        private void FrMain_FormClosed(object sender, FormClosedEventArgs e)
        {

            System.Diagnostics.Process.GetCurrentProcess().Kill();
            Application.Exit();
        }

        private void Mni_MayBao_Click(object sender, EventArgs e)
        {
            FrMayBao Fr = new FrMayBao();
            Fr.MdiParent = this;
            Fr.Show();
            //Fr.Users(lb_User.Text);
        }
       
        public void show_frgridview(DataTable dt)
        {
            FrGridview Fr = new FrGridview();
            Fr.MdiParent = this;
            Fr.Show();
            Fr.datagrid(dt);
            //Fr.Users(lb_User.Text);
        }
       
    }
}
